home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 November / Chip Kasım 2003.iso / prog / openoff / f_0153 / FilesModul.xba < prev    next >
Encoding:
Extensible Markup Language  |  2003-03-13  |  23.3 KB  |  685 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="FilesModul" script:language="StarBasic">Option Explicit
  4.  
  5. Public AbsTemplateFound as Integer
  6. Public AbsDocuFound as Integer
  7. Public oLogDocument as Object
  8. Public oLogTable as Object
  9. Public bLogExists as Boolean
  10. Public sComment as String
  11. Public MaxCollectIndex as Integer
  12. Public bInsertRow as Boolean
  13. Public sLogUrl as String
  14. Public sCurPassWord as String
  15. Public FileCount as Integer
  16. Public XMLTemplateCount as Integer
  17. Public PathCollection(7,3) as String
  18.  
  19.  
  20.  
  21. Function ReadCollectionPaths(FilesList() as String, sFilterName() as String)
  22. Dim FilterIndex as Integer
  23. Dim bRecursive as Boolean
  24. Dim SearchDir as String
  25. Dim i as Integer
  26. Dim n as Integer
  27. Dim a as Integer
  28. Dim s as Integer
  29. Dim sFileContent() as String
  30. Dim NewList(0,1) as String
  31. Dim Index as Integer
  32. Dim CurFileName as String
  33. Dim CurExtension as String
  34. Dim CurFileContent as String
  35. Dim XMLTemplateContentList() as String
  36. Dim bIsTemplatePath as Boolean
  37. Dim MaxIndex as Integer
  38. Dim NewContentList() as String
  39. Dim XMLTemplateContentString as String
  40. Dim ApplIndex as Integer
  41. Dim bAssignFileName as Boolean
  42.     oDocInfo = CreateUnoService("com.sun.star.document.DocumentProperties")
  43.     bInterruptSearch = False
  44.     For i = 0 To MaxCollectIndex
  45.         SearchDir = PathCollection(i,0)
  46.         bRecursive = PathCollection(i,1)
  47.         sFileContent() = ArrayoutofString(PathCollection(i,2), "|")
  48.         NewList() = ReadDirectories(SearchDir, bRecursive, False, False, sFileContent(), "")
  49.         If InterruptProcess Then
  50.             ReadCollectionPaths() = False
  51.             Exit Function
  52.         End If
  53.         If Ubound(NewList()) > -1 Then
  54.             bIsTemplatePath = FieldInList("vor", sFileContent)
  55.             If bIsTemplatePath Then
  56.                 XMLTemplateContentString = PathCollection(i,3)
  57.                 XMLTemplateContentList() = ArrayoutofString(XMLTemplateContentString, "|")
  58.                 If Ubound(XMLTemplateContentList()) > -1 Then
  59.                     MaxIndex = Ubound(NewList())
  60.                     ReDim Preserve NewList(MaxIndex, 1) as String
  61.                     ReDim Preserve NewContentList(MaxIndex) as String
  62.                     a = -1
  63.                     For n = 0 To MaxIndex
  64.                         bAssignFileName = True
  65.                         If InterruptProcess() Then
  66.                             ReadCollectionPaths() = False
  67.                             Exit Function
  68.                         End If
  69.                         CurFileName = NewList(n,0)                                                    
  70.                         If NewList(n,1) = "vor" Then
  71.                             CurFileContent = GetRealFileContent(oDocInfo, CurFileName)
  72.                             NewList(n,1) = CurFileContent
  73.                             bAssignFileName = FieldInList(CurFileContent, XMLTemplateContentList()) 
  74.                         End If
  75.                         CurExtension = NewList(n,1)
  76.                         If bAssignFileName Then
  77.                             If a < n Then
  78.                                 a = a + 1
  79.                                 NewList(a,0) = CurFileName
  80.                                 NewList(a,1) = CurExtension
  81.                                 ApplIndex = GetApplicationIndex(CurFileContent, sFiltername())
  82.                                 NewContentList(a) = ApplIndex
  83.                             End If
  84.                         End If
  85.                     Next n
  86.                     If a < MaxIndex Then
  87.                         ReDim Preserve NewList(a, 1) as String
  88.                     End If
  89.                     AddListtoFilesList(FilesList(), NewList(), NewContentList())
  90.                 End If
  91.             Else
  92.                 MaxIndex = Ubound(NewList())
  93.                 ReDim Preserve NewContentList(MaxIndex) as String
  94.                 For s = 0 To MaxIndex
  95.                     CurExtension = NewList(s,1)
  96.                     NewContentList(s) = GetApplicationIndex(CurExtension, sFiltername())
  97.                 Next s
  98.                 AddListtoFilesList(FilesList(), NewList(), NewContentList())
  99.             End If
  100.         End If
  101.     Next i
  102. End Function
  103.  
  104.  
  105. Function GetApplicationIndex(CurFileContent as String, sFilterName() as String) as Integer
  106. Dim Index as Integer
  107. Dim i as Integer
  108.     Index = GetIndexForPartStringinMultiArray(sFilterName(), CurFileContent, 0)
  109.     If Index >= MaxApplCount Then
  110.         Index = Index - MaxApplCount
  111.     End If
  112.     For i = 0 To MaxApplCount - 1
  113.         If Applications(i, SBAPPLKEY) = Index Then
  114.             GetApplicationIndex() = i
  115.             Exit Function
  116.         End If
  117.     Next i
  118.     GetApplicationIndex() = - 1
  119. End Function
  120.  
  121.  
  122. Function InterruptProcess() as Boolean
  123.     If bCancelTask Or RetValue = 0 Then
  124.         bConversionIsRunning = False
  125.         InterruptProcess() = True
  126.         Exit Function
  127.     End if        
  128.     InterruptProcess() = False
  129. End Function
  130.  
  131.  
  132. Sub AddCollectionPath(ApplIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  133.     MaxCollectIndex = MaxCollectIndex + 1
  134.     PathCollection(MaxCollectIndex, 0) = Applications(ApplIndex, DocIndex)
  135.     PathCollection(MaxCollectIndex, 1) = Applications(ApplIndex, RecursiveIndex)
  136.     AddFilterNameToPathItem(ApplIndex, MaxCollectIndex, sFiltername(), DistIndex)
  137. End Sub
  138.  
  139.  
  140. Sub AddFilterNameToPathItem(ApplIndex as Integer, CollectIndex as Integer, sFiltername() as String, DistIndex as Integer)
  141. Dim iKey as Integer
  142. Dim CurListString as String
  143. Dim LocExtension as String
  144. Dim LocContentString as String
  145. Dim LocXMLTemplateContent as String
  146.     iKey = Applications(ApplIndex, SBAPPLKEY)
  147.     CurListString = PathCollection(CollectIndex, 2)
  148.     LocExtension = sFilterName(iKey +DistIndex, 0)
  149.     If Len(LocExtension) > SBMAXEXTENSIONLENGTH Then             ' 7 == Length of two extensions like 'sda|sdd
  150.         LocExtension = "vor"
  151.         LocContentString = sFilterName(iKey +DistIndex, 0)
  152.         LocContentString = ReplaceString(LocContentString, "|", ";")
  153.         LocXMLTemplateContent = PathCollection(CollectIndex, 3)
  154.         If LocXMLTemplateContent = "" Then
  155.             LocXMLTemplateContent = LocContentString
  156.         Else
  157.             LocXMLTemplateContent = LocXMLTemplateContent & "|" & LocContentString
  158.         End If
  159.         PathCollection(CollectIndex, 3) = LocXMLTemplateContent
  160.     End If
  161.     If CurListString = "" Then
  162.         PathCollection(CollectIndex, 2) = LocExtension
  163.     Else
  164.         If Instr(CurListString, LocExtension) = 0 Then
  165.             PathCollection(CollectIndex, 2) = CurListString & "|" & LocExtension
  166.         End If
  167.     End If
  168. End Sub
  169.  
  170.  
  171. Sub CheckIfToAddPathToCollection(ApplIndex as Integer, bDoConvertIndex as Integer, DocIndex as Integer, RecursiveIndex as Integer, sFiltername() as String, DistIndex as Integer)
  172. Dim CollectIndex as Integer
  173. Dim bCheckDocuType as Boolean
  174.     bCheckDocuType = Applications(ApplIndex, bDoConvertIndex)
  175.     If bCheckDocuType Then
  176.         CollectIndex = GetIndexInMultiArray(PathCollection(), Applications(ApplIndex,DocIndex), 0)
  177.         If (CollectIndex >-1) Then
  178.             If Applications(ApplIndex, RecursiveIndex) <> PathCollection(CollectIndex, 1) Then
  179.                 AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  180.             Else
  181.                 AddFilterNameToPathItem(ApplIndex, CollectIndex, sFilterName(), DistIndex)
  182.             End If
  183.         Else
  184.             AddCollectionPath(ApplIndex, DocIndex, RecursiveIndex, sFilterName(), DistIndex)
  185.         End If
  186.     End If
  187. End Sub
  188.  
  189.  
  190. Sub CollectPaths(sFiltername() as String)
  191. Dim i as Integer
  192. Dim    XMLTemplateContentString as String
  193.     MaxCollectIndex = -1
  194.     For i = 0 To ApplCount-1
  195.         CheckIfToAddPathToCollection(i, SBDOCCONVERT, SBDOCSOURCE, SBDOCRECURSIVE, sFilterName(), 0)
  196.     Next i
  197.     XMLTemplateCount = 0
  198.     XMLTemplateContentString = ""
  199.     For i = 0 To ApplCount-1
  200.         If WizardMode = SBXMLMODE Then
  201.             XMLTemplateCount = XMLTemplateCount + 1
  202.         End If
  203.         CheckIfToAddPathToCollection(i, SBTEMPLCONVERT, SBTEMPLSOURCE, SBTEMPLRECURSIVE, sFilterName(), MaxApplCount)
  204.     Next i
  205. End Sub
  206.  
  207.  
  208. Sub ConvertAllDocuments(sFilterName() as String)
  209. Dim FileProperties(1) as new com.sun.star.beans.PropertyValue
  210. Dim PWFileProperties(2) as New com.sun.star.beans.PropertyValue
  211. Dim WriterWebProperties(0) as new com.sun.star.beans.PropertyValue
  212. Dim OpenProperties(4) as new com.sun.star.beans.PropertyValue
  213. Dim    oInteractionHandler as Object
  214. Dim InteractionTypes(0) as Long
  215. Dim FilesList(0,2) as String
  216. Dim sViewPath as String
  217. Dim i as Integer
  218. Dim FilterIndex as Integer
  219. Dim sSourceUrl as String
  220. Dim CurFilename as String
  221. Dim oDocument as Object
  222. Dim sExtension as String
  223. Dim OldExtension as String
  224. Dim CurFound as Integer
  225. Dim TotFound as Integer
  226. Dim TargetStemDir as String
  227. Dim SourceStemDir as String
  228. Dim TargetDir as String
  229. Dim sTargetUrl as String
  230. Dim CurFilterName as String
  231. Dim ApplIndex as Integer
  232. Dim Index as Integer
  233. Dim bIsDocument as Boolean
  234. Dim bDoSave as Boolean
  235. Dim sCurFileExists as String
  236. Dim MaxFileIndex as Integer
  237. Dim bContainsBasicMacro as Boolean
  238. Dim bIsPassWordProtected as Boolean
  239. Dim iOverwrite as Integer
  240.     bConversionisrunning = True
  241.     InteractionTypes(0) = com.sun.star.task.PasswordRequestMode.PASSWORD_REENTER
  242.     oInteractionHandler = createUnoService("com.sun.star.task.InteractionHandler")
  243.     oInteractionHandler.initialize(InteractionTypes())
  244.     iGeneralOverwrite = SBOVERWRITEUNDEFINED
  245.     bConversionIsRunning = True
  246.     bLogExists = false
  247.     AbsTemplateFound = 0
  248.     AbsDocuFound = 0
  249.     CollectPaths(sFiltername())
  250.     If Not ReadCollectionPaths(FilesList(), sFilterName()) Then
  251.         TotFound = 0
  252.         SetProgressDisplay(0)
  253.         bConversionisrunning = false
  254.         FinalizeDialogButtons()    
  255.         Exit Sub
  256.     End If
  257.     TotFound = Ubound(FilesList()) + 1             
  258.     If FilesList(0,0) = "" Then                    ' Querying the number of fields in a multidimensionl Array is unsecure
  259.         TotFound = 0                            ' because it will return the value 0 (and not -1) even when the Array is empty
  260.         SetProgressDisplay(0)
  261.     End If
  262.     If TotFound > 0 Then
  263.         CreateLogDocument(OpenProperties())
  264.         InitializeProgressPage(ImportDialog)
  265.         OpenProperties(0).Name = "Hidden"
  266.         OpenProperties(0).Value = True
  267.         OpenProperties(1).Name = "AsTemplate"
  268.         OpenProperties(1).Value = False
  269.         OpenProperties(2).Name = "MacroExecutionMode"
  270.         OpenProperties(2).Value = com.sun.star.document.MacroExecMode.NEVER_EXECUTE    
  271.         OpenProperties(3).Name = "UpdateDocMode"
  272.         OpenProperties(3).Value = com.sun.star.document.UpdateDocMode.NO_UPDATE
  273.         OpenProperties(4).Name = "InteractionHandler"
  274.         OpenProperties(4).Value = oInteractionHandler
  275.         MaxFileIndex = Ubound(FilesList(),1)
  276.         FileCount = 0
  277.         For i = 0 To MaxFileIndex
  278.             sComment = ""
  279.             If InterruptProcess() Then
  280.                 Exit For
  281.             End If
  282.             bDoSave = True
  283.             sSourceUrl = FilesList(i,0)
  284.             CurFiltername =    GetFilterName(FilesList(i,1), sFilterName(), sExtension, FilterIndex)
  285.             ApplIndex = FilesList(i,2)
  286.             If ApplIndex > Ubound(Applications) or (ApplIndex < 0) Then
  287.                 Msgbox "Applicationindex out of bounds:" & sSourcUrl
  288.             End If
  289.             sViewPath = ConvertFromUrl(sSourceUrl)     ' CutPathView(sSourceUrl, 70)
  290.             ImportDialog.LabelCurDocument.Label = Str(i+1) & "/" & MaxFileIndex + 1 & "  (" & sViewPath & ")"
  291.             Select Case lcase(sExtension)
  292.                 Case "sxw", "sxc", "sxi", "sxd", "sxs", "sxm"
  293.                     SourceStemDir = RTrimStr(Applications(ApplIndex,SBDOCSOURCE), "/")
  294.                     TargetStemDir = RTrimStr(Applications(ApplIndex,SBDOCTARGET), "/")
  295.                 Case Else                                 ' Templates and Helper-Applications remain
  296.                     SourceStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLSOURCE), "/")
  297.                     TargetStemDir = RTrimStr(Applications(ApplIndex,SBTEMPLTARGET), "/")
  298.             End Select
  299.             sTargetUrl = ReplaceString(sSourceUrl, TargetStemDir, SourceStemDir)
  300.             CurFilename = GetFileNameWithoutExtension(sTargetUrl, "/")
  301.             OldExtension = GetFileNameExtension(sTargetUrl)
  302.             sTargetUrl = RTrimStr(sTargetUrl, OldExtension)
  303.             sTargetUrl = sTargetUrl & sExtension
  304.             TargetDir = RTrimStr(sTargetUrl, CurFilename & "." & sExtension)
  305.             If (oUcb.Exists(sTargetUrl)) Then
  306.                 If (iGeneralOverwrite <> SBOVERWRITEALWAYS) Then
  307.                     If (iGeneralOverwrite = SBOVERWRITEUNDEFINED) Then
  308.                         ShowOverwriteAllDialog(sTargetUrl, sTitle)
  309.                         bDoSave = (iGeneralOverwrite = SBOVERWRITEQUERY) Or (iGeneralOverwrite = SBOVERWRITEALWAYS)
  310.                     Elseif iGeneralOverwrite = SBOVERWRITENEVER Then
  311.                         bDoSave = False                    
  312.                     ElseIf ((iGeneralOverWrite = SBOVERWRITEQUERY) OR (iGeneralOverwrite = SBOVERWRITECANCEL)) Then
  313.                         ' Todo: According to AS there might come a new feature that storeasUrl could possibly rise a UI dialog. 
  314.                         ' In this case my own UI becomes obsolete
  315.                         sCurFileExists = ReplaceString(sFileExists, ConvertFromUrl(sTargetUrl), "<1>")
  316.                         sCurFileExists = ReplaceString(sCurFileExists, chr(13), "<CR>")
  317.                         iOverWrite = Msgbox (sCurFileExists, 32 + 3, sTitle)
  318.                         Select Case iOverWrite
  319.                             Case 1    ' OK
  320.                                 ' In the FileProperty-Bean this is already default
  321.                                 bDoSave = True
  322.                             Case 2     ' Abort
  323.                                 CancelTask(False)
  324.                                 bDoSave = False
  325.                             Case 7     ' No
  326.                                 bDoSave = False
  327.                         End Select
  328.                     End If
  329.                 End If
  330.             End If
  331.             If bDoSave Then
  332.                 If Not oUcb.Exists(TargetDir) Then
  333.                     bDoSave = CreateFolder(TargetDir)
  334.                 End If
  335.                 If bDoSave Then
  336.                     oDocument = StarDesktop.LoadComponentFromURL(sSourceUrl, "_default", 0, OpenProperties())
  337.                     If Not IsNull(oDocument) Then
  338.                         InsertSourceUrlToLogDocument(sSourceUrl, "")
  339.                         bIsPassWordProtected = CheckPassWordProtection(oDocument)
  340.                         CheckIfMacroExists(oDocument.BasicLibraries, sComment)
  341.                         On Local Error Goto NOSAVING
  342.                         ' Todo: Due to bug #93651 the handling of the fileProperties has to be handled without Redimensioning
  343.                         If bIsPassWordProtected Then
  344.                             PWFileProperties(0).Name = "FilterName"
  345.                             PWFileProperties(0).Value = CurFilterName
  346.                             PWFileProperties(1).Name = "Overwrite"
  347.                             PWFileProperties(1).Value = True
  348.                             PWFileProperties(2).Name = "Password"
  349.                             PWFileProperties(2).Value = sCurPassWord
  350.                             oDocument.StoreAsUrl(sTargetUrl, PWFileProperties())
  351.                         Else
  352.                             FileProperties(0).Name = "FilterName"
  353.                             FileProperties(0).Value = CurFilterName
  354.                             FileProperties(1).Name = "Overwrite"
  355.                             FileProperties(1).Value = True
  356.                             oDocument.StoreAsUrl(sTargetUrl,FileProperties())
  357.                         End If
  358.                         ' Todo: Make sure that an errorbox pops up when saving fails
  359.                         NOSAVING:
  360.                         If Err <> 0 Then
  361.                             sCurcouldnotsaveDocument = ReplaceString(scouldnotsaveDocument, ConvertFromUrl(sTargetUrl), "<1>")
  362.                             sComment = ConcatComment(sComment, sCurCouldnotsaveDocument)
  363.                             Resume LETSGO
  364.                             LETSGO:
  365.                         Else
  366.                             FileCount = FileCount + 1
  367.                         End If
  368.                         oDocument.Dispose()
  369.                         InsertTargetUrlToLogDocument(sTargetUrl, sComment)
  370.                     Else
  371.                         sCurcouldnotopenDocument = ReplaceString(scouldnotopenDocument, ConvertFromUrl(sSourceUrl), "<1>")
  372.                         sComment = ConcatComment(sComment, sCurCouldnotopenDocument)
  373.                         InsertSourceUrlToLogDocument(sSourceUrl, sComment)                
  374.                     End If
  375.                 End If
  376.             End If
  377.         Next i
  378.     End If
  379.     AddLogStatistics()
  380.     FinalizeDialogButtons()
  381.     bConversionIsRunning = False
  382.     Exit Sub
  383. RTError:
  384.     Msgbox sRTErrorDesc, 16, sRTErrorHeader
  385. End Sub
  386.  
  387.  
  388.  
  389. Sub AddListtoFilesList(FirstList(), SecList(), NewContentList() as String)
  390. Dim sLocExtension as String
  391. Dim FirstStart as Integer
  392. Dim FirstEnd as Integer
  393. Dim i as Integer
  394. Dim s as Integer
  395.     If FirstList(0,0) = "" Then
  396.         FirstStart = Ubound(FirstList(),1)
  397.     Else
  398.         FirstStart = Ubound(FirstList(),1) + 1
  399.     End If
  400.     FirstEnd = FirstStart + Ubound(SecList(),1)
  401.     ReDim Preserve FirstList(FirstEnd,2)
  402.     s = 0
  403.     For i = FirstStart To FirstEnd
  404.         FirstList(i,0) = SecList(s,0)
  405.         FirstList(i,1) = SecList(s,1)
  406.         sLocExtension = lcase(FirstList(i,1))
  407.         Select Case sLocExtension
  408.             Case "sdw", "sdc", "sda", "sdd", "smf", "sgl", "doc", "xls", "ppt"
  409.                 AbsDocuFound = AbsDocuFound + 1
  410.             Case else
  411.                 AbsTemplateFound = AbsTemplateFound + 1
  412.         End Select
  413.         FirstList(i,2) = CStr(NewContentList(s))
  414.         s = s + 1
  415.     Next i
  416.     SetProgressDisplay(Ubound(FirstList()) + 1)
  417. End Sub
  418.  
  419.  
  420.  
  421. Function GetTargetTemplatePath(Index as Integer)
  422.     Select Case WizardMode
  423.         Case SBMICROSOFTMODE
  424.             GetTargetTemplatePath() = SOTemplatePath & "/" & sTemplateGroupName
  425.         Case SBXMLMODE
  426.             If Index = 3 Then
  427.                 ' Helper Application
  428.                 GetTargetTemplatePath = SOWorkPath
  429.             Else
  430.                 GetTargetTemplatePath = SOTemplatePath
  431.             End If
  432.     End Select
  433. End Function
  434.  
  435.  
  436. ' Retrieves the second value for a next to 'SearchString' in
  437. ' a two-dimensional string-Array
  438. Function GetFilterName(sMimetypeorExtension as String, sFilterName(), sExtension as string, FilterIndex as Integer) as String
  439. Dim i as Integer
  440. Dim MaxIndex as Integer
  441. Dim sLocFilterlist() as String
  442.     For i = 0 To Ubound(sFiltername(),1)
  443.         If Instr(1,sFilterName(i,0),sMimeTypeOrExtension) <> 0 Then
  444.             sLocFilterList() = ArrayoutofString(sFiltername(i,0),"|", MaxIndex)
  445.             If MaxIndex = 0 Then
  446.                 sExtension = sFiltername(i,2)
  447.                 GetFilterName = sFilterName(i,1)
  448.             Else
  449.                 Dim b as Integer
  450.                 Dim sLocExtensionList() as String
  451.                 b =    SearchArrayForPartString(sMimetypeOrExtension, sLocFilterList())
  452.                 sLocFilterList() = ArrayoutofString(sFiltername(i,1),"|", MaxIndex)
  453.                 GetFilterName = sLocFilterList(b)
  454.                 sLocExtensionList() = ArrayoutofString(sFilterName(i,2), "|", MaxIndex)
  455.                 sExtension = sLocExtensionList(b)
  456.             End If
  457.             Exit For
  458.         End If
  459.     Next
  460.     FilterIndex = i
  461. End Function
  462.  
  463.  
  464. Function SearchArrayforPartString(SearchString as String, LocList()) as Integer
  465. Dim i as integer
  466.     For i = Lbound(LocList(),1) to Ubound(LocList(),1)
  467.         If Instr(1,LocList(i), SearchString) <> 0 Then
  468.             SearchArrayForPartString() = i
  469.             Exit Function
  470.         End if
  471.     Next
  472.     IndexinArray = -1
  473. End Function
  474.  
  475.  
  476. Function GetMimeTypeList(BigFiltername as STring)
  477. Dim sBigList() as String
  478. Dim sSmallList() as String
  479. Dim sMimeTypeList()
  480. Dim BigMaxIndex as Integer
  481. Dim n as Integer
  482.     sBigList() = ArrayoutofString(BigFilterName,"|", BigMaxIndex)
  483.     For n = 0 To BigMaxIndex
  484.         sSmallList() = ArrayoutofString(sBigList(n),";")
  485.         sMimeTypeList() = AddListToList(sMimeTypeList(), sSmallList())
  486.     Next n
  487.     GetMimetypeList() = sMimeTypeList()
  488. End Function
  489.  
  490.  
  491. Sub CreateLogDocument(HiddenProperties())
  492. Dim OpenProperties(0) as new com.sun.star.beans.PropertyValue
  493. Dim oTableCursor as Object
  494. Dim oLogCursor as Object
  495. Dim oLogRows as Object
  496. Dim NoArgs()
  497. Dim i as Integer
  498. Dim bLogIsThere as Boolean
  499.     If ImportDialog.chkLogfile.State = 1 Then
  500.         i = 2
  501.         OpenProperties(0).Name = "Hidden"
  502.         OpenProperties(0).Value = True
  503.         oLogDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter", "_default", 4, OpenProperties())
  504.         oLogCursor = oLogDocument.Text.CreateTextCursor
  505.         oLogTable =  oLogDocument.CreateInstance("com.sun.star.text.TextTable")
  506.         oLogTable.RepeatHeadline = true
  507.         oLogCursor.Text.InsertTextContent(oLogCursor, oLogTable, True)
  508.         oLogCursor = oLogTable.GetCellbyPosition(0,0).createTextCursor()
  509.         oLogCursor.SetString(sSourceDocuments)
  510.         oLogCursor = oLogTable.GetCellbyPosition(1,0).createTextCursor()
  511.         oLogCursor.SetString(sTargetDocuments)
  512.         bInsertRow = False
  513.         sLogUrl = SOWorkPath & "/Logfile.sxw"
  514.         Do
  515.             bLogIsThere = oUcb.Exists(sLogUrl)
  516.             If bLogIsThere Then
  517.                 If i = 2 Then
  518.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_2.sxw", "/Logfile.sxw")
  519.                 Else
  520.                     sLogUrl = ReplaceString(sLogUrl, "/Logfile_" & cStr(i) & ".sxw", "/Logfile_" & cStr(i-1) & ".sxw")
  521.                 End If
  522.                 i = i + 1
  523.             End If
  524.         Loop Until Not bLogIsThere
  525.         bLogExists = True
  526.         oLogDocument.StoreAsUrl(sLogUrl, NoArgs())
  527.     End If
  528. End Sub
  529.  
  530.  
  531. Sub InsertTargetUrlToLogDocument(sTargetUrl as String, sComment as String)
  532. Dim oCell as Object
  533.     If (bLogExists) And (sTargetUrl <> "") Then
  534.         If sTargetUrl <> "" Then
  535.             oCell = oLogTable.GetCellbyPosition(1,oLogTable.Rows.Count-1)
  536. '            If ((TargetUrl <>"") AND (i = 1)) Or ((TargetUrl = "") AND (i = 0)) Then
  537.                 InsertCommentToLogCell(sComment, oCell)
  538. '            End  If
  539.             InsertHyperLinkToLogCell(sTargetUrl, oCell)
  540.             oLogDocument.Store()
  541.         End If
  542.     End If
  543. End Sub
  544.  
  545.  
  546. Sub InsertSourceUrlToLogDocument(SourceUrl as String, sComment)        '
  547. Dim oCell as Object
  548.     If bLogExists Then
  549.         If bInsertRow Then
  550.             oLogTable.Rows.InsertByIndex(oLogTable.Rows.Count,1)
  551.         Else
  552.             bInsertRow = True
  553.         End If
  554.         oCell = oLogTable.GetCellbyPosition(0,oLogTable.Rows.Count-1)
  555.         InsertCommentToLogCell(sComment, oCell)
  556.         InsertHyperLinkToLogCell(SourceUrl, oCell)
  557.         oLogDocument.Store()
  558.     End If
  559. End Sub
  560.  
  561.  
  562. Sub InsertHyperLinkToLogCell(sUrl as String, oCell as Object)
  563. Dim oLogCursor as Object
  564. Dim LocFileName as String
  565.     oLogCursor = oCell.createTextCursor()
  566.     oLogCursor.CollapseToStart()
  567.     oLogCursor.HyperLinkURL = sUrl
  568.     oLogCursor.HyperLinkName = sUrl
  569.     oLogCursor.HyperLinkTarget = sUrl
  570.     LocFileName = FileNameOutOfPath(sUrl)
  571.     oCell.InsertString(oLogCursor, LocFileName,False)
  572. End Sub            
  573.  
  574.  
  575. Sub InsertCommentToLogCell(sComment as string, oCell as Object)
  576. Dim oCommentCursor as Object
  577.     If sComment <> "" Then
  578.         oCommentCursor = oCell.createTextCursor()
  579.         oCell.insertControlCharacter(oCommentCursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
  580.         oCell.insertString(oCommentCursor, sComment, false)
  581.     End If
  582. End Sub
  583.  
  584.  
  585. Sub AddLogStatistics()
  586. Dim oCell as Object
  587. Dim oLogCursor as Object
  588. Dim MaxRowIndex as Integer
  589.     If bLogExists Then
  590.         MaxRowIndex = oLogTable.Rows.Count
  591.         sLogSummary = ReplaceString(sLogSummary, FileCount, "<COUNT>")
  592.         oLogTable.Rows.InsertByIndex(MaxRowIndex, 1)
  593.         oCell = oLogTable.GetCellbyPosition(0, MaxRowIndex)
  594.         oLogCursor = oCell.createTextCursor()
  595.         oCell.InsertString(oLogCursor, sLogSummary,False)
  596.         MergeRange(oLogTable, oCell, 1)        
  597.         oLogDocument.Store()
  598.         oLogDocument.Dispose()
  599.         bLogExists = False
  600.     End If
  601. End Sub
  602.  
  603.  
  604.  
  605. Function CheckIfMacroExists(oBasicLibraries as Object, sComment as String) as Boolean
  606. Dim ModuleNames() as String
  607. Dim ModuleName as String
  608. Dim MaxLibIndex as Integer
  609. Dim MaxModuleIndex as Integer
  610. Dim bMacroExists as Boolean
  611. Dim n as Integer
  612. Dim m as Integer
  613. Dim LibName as String
  614. Dim sBasicCode as String
  615. Dim oLibrary as Object
  616.     bMacroExists = False
  617.     bMacroExists = oBasicLibraries.hasElements
  618.     If bMacroExists Then
  619.         MaxLibIndex = Ubound(oBasicLibraries.ElementNames())
  620.         For n = 0 To MaxLibIndex
  621.             LibName = oBasicLibraries.ElementNames(n)
  622.             oLibrary = oBasicLibraries.getbyName(LibName)
  623.             If oLibrary.hasElements() Then
  624.                 MaxModuleIndex = Ubound(oLibrary.ElementNames())
  625.                 For m = 0 To MaxModuleIndex
  626.                     ModuleName = oLibrary.ElementNames(m)
  627.                     sBasicCode = oLibrary.getbyName(ModuleName)
  628.                     If sBasicCode <> "" Then
  629.                         ConcatComment(sComment, sReeditMacro)
  630.                         CheckIfMacroExists() = True
  631.                         Exit Function
  632.                     End If
  633.                 Next m
  634.             End If
  635.         Next n
  636.     End If
  637.     CheckIfMacroExists() = False
  638. End Function
  639.  
  640.  
  641.  
  642. Function CheckPassWordProtection(oDocument as Object)
  643. Dim bIsPassWordProtected as Boolean
  644. Dim i as Integer
  645. Dim oArgs()
  646. Dim MaxIndex as Integer
  647. Dim sblabla as String
  648.     bIsPassWordProtected = false
  649.      oArgs() = oDocument.getArgs()
  650.      MaxIndex = Ubound(oArgs())
  651.     For i = 0 To MaxIndex
  652.         sblabla = oArgs(i).Name
  653.         If oArgs(i).Name = "Password" Then
  654.             bIsPassWordProtected = True
  655.             sCurPassWord = oArgs(i).Value
  656.             Exit For
  657.         End If
  658.     Next i
  659.     CheckPassWordProtection() = bIsPassWordProtected
  660. End Function
  661.  
  662.  
  663. Sub OpenLogDocument()
  664. Dim NoArgs() as New com.sun.star.beans.PropertyValue
  665.     OpenDocument(sLogUrl, NoArgs())
  666. End Sub
  667.  
  668.  
  669. Sub MergeRange(oTable as Object, oCell as Object, MergeCount as Integer)    
  670. Dim oTableCursor as Object
  671.     oTableCursor = oTable.createCursorByCellName(oCell.CellName)
  672.     oTableCursor.goRight(MergeCount, True)
  673.     oTableCursor.mergeRange()
  674. End Sub        
  675.  
  676.  
  677. Function ConcatComment(sComment as String, AdditionalComment as String)
  678.     If sComment = "" Then
  679.         sComment = AdditionalComment
  680.     Else
  681.         sComment = sComment & chr(13) + AdditionalComment
  682.     End If                
  683.     ConcatComment = sComment
  684. End Function
  685. </script:module>